import Vue from 'vue'
import VueRouter from 'vue-router'
import store from './../store/index.js'

Vue.use(VueRouter)

let router = new VueRouter({
  base: '/microapp',
  routes: [
    {
      path: '/preview',
      component: resolve => require(['../view/preview/preview.vue'], resolve),
      meta: {
        title: '预览模式'
      }
    },
    {
      path: '/home',
      component: resolve => require(['../view/home/home.vue'], resolve),
      children: [
        /* 基本信息 */
        {
          path: '/basic',
          meta: {
            title: '基本信息'
          },
          component: resolve => require(['../view/basic/basic.vue'], resolve)
        },
        /* 商品管理 */
        {
          path: '/goods',
          redirect: '/goods/home'
        },
        {
          path: '/goods/home',
          meta: {
            title: '商品管理'
          },
          component: resolve => require(['../view/goods/goods.vue'], resolve)
        },
        {
          path: '/goods/edit/:id',
          component: resolve => require(['../view/goods/detail.vue'], resolve),
          meta: {
            title: '编辑商品'
          }
        },
        {
          path: '/goods/add',
          component: resolve => require(['../view/goods/detail.vue'], resolve),
          meta: {
            title: '新增商品'
          }
        },
        /* 门店管理 */
        {
          path: '/stores',
          redirect: '/stores/home'
        },
        {
          path: '/stores/home',
          meta: {
            title: '门店管理'
          },
          component: resolve => require(['../view/stores/stores.vue'], resolve)
        },
        {
          path: '/stores/edit/:id',
          meta: {
            title: '编辑门店'
          },
          component: resolve => require(['../view/stores/detail.vue'], resolve)
        },
        {
          path: '/stores/add',
          meta: {
            title: '新增门店'
          },
          component: resolve => require(['../view/stores/detail.vue'], resolve)
        },
        {
          path: '/help',
          meta: {
            title: '帮助中心'
          },
          component: resolve => require(['../view/help/help.vue'], resolve)
        },
        {
          path: '/help/answer/:step',
          meta: {
            title: '帮助中心'
          },
          component: resolve => require(['../view/help/answer.vue'], resolve)
        }
      ]
    }
  ]
})

router.beforeEach((to, from, next) => {
  store.dispatch('loadingStatus', true)
  next()
})

router.afterEach((to, from) => {
  store.dispatch('loadingStatus', false)
})

export default router
